"""
Case Type   : show collation
Case Name   : 查询所有字符序
Create At   : 2024/10/25
Owner       : lonely-dance
Description :
    1.查询字符序
    2.使用查询到的字符序建库
    3.清理环境
Expect      :
    1.成功
    2.成功
    3.成功
History     :
"""
import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class ShowCollation(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.pri_b_sh = CommonSH('PrimaryDbBmode')
        self.constant = Constant()

    def test_show_collation(self):
        text = '-----step1:查询字符序 expect:查询成功-----'
        self.log.info(text)
        cmd = """
            set dolphin.b_compatibility_mode = off;
            show collation;
        """
        self.log.info(cmd)
        res = self.pri_b_sh.execut_db_sql(cmd)
        self.log.info(res)
        self.assertTrue('ERROR' not in res
                        and 'zh_HK.utf8' in res
                        and 'zh_CN.utf8' in res, '执行失败' + text)

        text = '-----step2:使用查询到的字符序建库 expect:成功-----'
        self.log.info(text)
        cmd = """
            set dolphin.b_compatibility_mode = off;
            drop database if exists test_database_001a;
            create database test_database_001a with lc_collate 'zh_HK.utf8';
            drop database if exists test_database_001b;
            create database test_database_001b with lc_collate 'zh_CN.utf8';
        """
        self.log.info(cmd)
        res = self.pri_b_sh.execut_db_sql(cmd)
        self.log.info(res)
        self.assertTrue(res.count(self.constant.CREATE_DATABASE_SUCCESS) == 2, '执行失败' + text)

    def tearDown(self):
        text = '-----step3:清理环境 expect:成功-----'
        self.log.info(text)
        cmd = """
            set dolphin.b_compatibility_mode = off;
            drop database test_database_001a;
            drop database test_database_001b;
        """
        self.log.info(cmd)
        res = self.pri_b_sh.execut_db_sql(cmd)
        self.log.info(res)
        self.assertTrue(res.count(self.constant.DROP_DATABASE_SUCCESS) == 2, '执行失败' + text)

        self.log.info(f'----{os.path.basename(__file__)} end----')
